package com.xisan.practice.proxy.jdk.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.time.LocalDateTime;

public class ProxyFactory {
    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }

    public Object proxyInstance(){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), (proxy, method, args) -> {
            System.out.println("计算开始时间" + LocalDateTime.now());
            // 执行目标方法
            method.invoke(target, args);
            System.out.println("计算结束时间" + LocalDateTime.now());
            return null;
        });
    }
}
